package com.shanzmoo.platform.server.api.web.merchant;

import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.util.JYFException;
import com.shanzmoo.db.module.merchant.domain.dto.*;
import com.shanzmoo.db.module.merchant.domain.query.*;
import com.shanzmoo.db.module.merchant.domain.vo.*;
import com.shanzmoo.db.module.merchant.domain.vo.base.MerchantBaseInfoVo;
import com.shanzmoo.platform.server.api.manager.MerchantInfoManage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 作者：zfj
 * @version 创建时间：2021年3月28日,0028
 * @classDesc 类描述
 */
@Slf4j
@Api(tags = "商户入驻")
@RestController
@RequestMapping("/merchantInfo")
@RequiredArgsConstructor
public class MerchantInfoController {

    // 入驻商户处理信息
    private final MerchantInfoManage merchantInfoManage;

    /**
     * 保存入驻商户信息
     *
     * @param merchantInfoDto 入驻商户信息
     * @return
     */
    @ApiOperation(value = "保存入驻商户信息")
    @PostMapping("/saveMerchantInfo")
    public SHttpResponse<Integer> saveMerchantInfo(@RequestBody MerchantInfoDto merchantInfoDto) {
        try {
            return merchantInfoManage.saveMerchantInfo(merchantInfoDto);
        } catch (JYFException e){
            log.error("保存入驻商户信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        }  catch (Exception e){
            log.error("保存入驻商户信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "保存入驻商户信息失败");
        }
    }

    /**
     * 查询入驻商户信息
     *
     * @param query 入驻商户查询条件信息
     * @return
     */
    @ApiOperation(value = "查询入驻商户明细信息")
    @PostMapping("/selectMerchantInfo")
    public SHttpResponse<MerchantInfoVo> selectMerchantInfo(@RequestBody MerchantInfoQuery query) {
        return merchantInfoManage.selectMerchantInfo(query);
    }

    /**
     * 获取行业类别信息
     *
     * @return
     */
    @ApiOperation(value = "获取行业类别信息")
    @PostMapping("/selectBusinessInfo")
    public SHttpResponse<List<BusinessVo>> selectBusinessInfo(@RequestBody BusinessQuery query) {
        return merchantInfoManage.selectBusinessInfo(query);
    }

    /**
     * 获取地区信息
     *
     * @return
     */
    @ApiOperation(value = "获取地区信息")
    @PostMapping("/selectAreaInfo")
    public SHttpResponse<List<AreaVo>> selectAreaInfo(@RequestBody AreaQuery query) {
        return merchantInfoManage.selectAreaInfo(query);
    }


    /**
     * 通过OCR识别获取图片识别信息
     *
     * @return
     */
    @ApiOperation(value = "通过OCR识别获取图片识别信息")
    @PostMapping("/selectOCRDistinguish")
    public SHttpResponse<MerchantOCRDistinguishVo> selectOCRDistinguish(@RequestBody MerchantOCRDistinguishQuery query) {
        return merchantInfoManage.selectOCRDistinguish(query);
    }

    /**
     * 通过银卡编码获取支行信息等
     *
     * @return
     */
    @ApiOperation(value = "通过银卡编码获取支行信息等")
    @PostMapping("/selectBank")
    public SHttpResponse<List<BankVo>> selectBank(@RequestBody BankQuery query) {
        return merchantInfoManage.selectBank(query);
    }

    /**
     * 发送短信信息
     *
     * @return
     */
    @ApiOperation(value = "发送短信信息")
    @PostMapping("/sendSmsMsg")
    public SHttpResponse<Boolean> sendSmsMsg(@RequestBody MerchantSmsInfoDto smsInfoVo) {
        return merchantInfoManage.sendSmsMsg(smsInfoVo);
    }

    /**
     * 验证短信信息
     *
     * @return
     */
    @ApiOperation(value = "验证短信信息")
    @PostMapping("/checkSmsMsg")
    public SHttpResponse<Boolean> checkSmsMsg(@RequestBody MerchantSmsInfoDto smsInfoVo) {
        return merchantInfoManage.checkSmsMsg(smsInfoVo);
    }

    /**
     * 修改电话号码
     *
     * @return
     */
    @ApiOperation(value = "修改电话号码")
    @PostMapping("/updateMerchantMobilePhone")
    public SHttpResponse<Boolean> updateMerchantMobilePhone(@RequestBody MerchantSmsInfoDto smsInfoVo) {
        try {
            return merchantInfoManage.updateMerchantMobilePhone(smsInfoVo);
        } catch (JYFException e){
            log.error("修改电话号码，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("修改电话号码异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "修改电话号码异常");
        }
    }

    /**
     * 修改邮箱信息
     *
     * @return
     */
    @ApiOperation(value = "修改邮箱信息")
    @PostMapping("/updateMerchantEmail")
    public SHttpResponse<Boolean> updateMerchantEmail(@RequestBody MerchantEmailInfoDto emailInfoDto) {
        try {
            return merchantInfoManage.updateMerchantEmail(emailInfoDto);
        } catch (JYFException e){
            log.error("修改邮箱信息，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("修改邮箱信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "修改邮箱信息异常");
        }
    }

    /**
     * 修改商户地址
     *
     * @return
     */
    @ApiOperation(value = "修改商户地址")
    @PostMapping("/updateMerchantAddressInfo")
    public SHttpResponse<Boolean> updateMerchantAddressInfo(@RequestBody MerchantAddressInfoDto addressInfo) {
        try {
            return merchantInfoManage.updateMerchantAddressInfo(addressInfo);
        } catch (JYFException e){
            log.error("修改商户地址异常，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("修改商户地址异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "修改商户地址异常");
        }
    }

    /**
     * 修改结算信息
     *
     * @return
     */
    @ApiOperation(value = "修改结算信息")
    @PostMapping("/updateMerchantSettlementInfo")
    public SHttpResponse<Boolean> updateMerchantSettlementInfo(@RequestBody MerchantSettlementInfoDto settlementInfo) {
        try {
            return merchantInfoManage.updateMerchantSettlementInfo(settlementInfo);
        } catch (JYFException e){
            log.error("修改结算信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("修改结算信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "修改结算信息异常");
        }
    }

    /**
     * 保存/修改门店信息
     *
     * @return
     */
    @ApiOperation(value = "保存/修改门店信息")
    @PostMapping("/saveMerchantShop")
    public SHttpResponse<Boolean> saveMerchantShopEntity(@RequestBody MerchantShopVo merchantShop) {
        try {
            return merchantInfoManage.saveMerchantShopEntity(merchantShop);
        } catch (JYFException e){
            log.error("保存/修改门店信息，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("保存/修改门店信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "更新门店信息失败");
        }
    }

    /**
     * 分页查询门店信息
     *
     * @return
     */
    @ApiOperation(value = "分页查询门店信息")
    @PostMapping("/selectMerchantShop")
    public SHttpResponse<PageRespBase<MerchantShopVo>> selectMerchantShop(@RequestBody MerchantShopQuery query) {
        return merchantInfoManage.selectMerchantShop(query);
    }

    /**
     * 查询门店详情信息
     *
     * @return
     */
    @ApiOperation(value = "查询门店详情信息")
    @PostMapping("/selectMerchantShopDetail")
    public SHttpResponse<MerchantShopVo> selectMerchantShopDetail(@RequestParam(value = "id") Integer id) {
        return merchantInfoManage.selectMerchantShopDetail(id);
    }


    /**
     * 保存/修改商户台卡信息
     *
     * @return
     */
    @ApiOperation(value = "保存/修改商户台卡信息")
    @PostMapping("/saveMerchantTerminal")
    public SHttpResponse<Boolean> saveMerchantTerminal(@RequestBody MerchantTerminalVo merchantTerminal) {
        try {
            return merchantInfoManage.saveMerchantTerminal(merchantTerminal);
        } catch (JYFException e){
            log.error("保存/修改商户台卡信息，异常信息为：{}", e);
            return SHttpResponse.fail(100004, e.getMessage());
        } catch (Exception e){
            log.error("更新台卡信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "更新台卡信息失败");
        }
    }

    /**
     * 开通或关闭商户台卡信息
     *
     * @return
     */
    @ApiOperation(value = "开通或关闭商户台卡信息")
    @PostMapping("/updateMerchantTerminal")
    public SHttpResponse<Boolean> updateMerchantTerminal(@RequestBody MerchantTerminalVo merchantTerminal) {
        try {
            return merchantInfoManage.updateMerchantTerminal(merchantTerminal);
        } catch (Exception e){
            log.error("更新台卡信息异常，异常信息为：{}", e);
            return SHttpResponse.fail(100003, "更新台卡信息失败");
        }
    }

    /**
     * 分页查询门店信息
     *
     * @return
     */
    @ApiOperation(value = "分页查询商户台卡信息")
    @PostMapping("/selectMerchantTerminal")
    public SHttpResponse<PageRespBase<MerchantTerminalVo>> selectMerchantTerminal(@RequestBody MerchantTerminalQuery query) {
        return merchantInfoManage.selectMerchantTerminal(query);
    }

    /**
     * 查询商户台卡详情信息
     *
     * @return
     */
    @ApiOperation(value = "查询商户台卡详情信息")
    @PostMapping("/selectMerchantTerminalDetail")
    public SHttpResponse<MerchantTerminalVo> selectMerchantTerminalDetail(@RequestParam(value = "id") Integer id) {
        return merchantInfoManage.selectMerchantTerminalDetail(id);
    }

}
